<template>
  <div class="main">
    <div class="Box">
      <div class="back" @click="back">《</div>
      <div class="contant">
        <div class="Title">
          兑换详情
          <div class="Stitle">Ways to convert</div>
        </div>
        <div class="orderBox">
          <div class="title">
            <div>配送方式</div>
            <div>
              <el-radio-group v-model="radio">
                <el-radio disabled :label="3">邮寄</el-radio>
                <!-- <el-radio disabled :label="6">自提</el-radio> -->
              </el-radio-group>
            </div>
          </div>
          <div v-if="radio == 3">
            <div class="titleBox">
              <div>联系人:</div>
              <input
                disabled
                class="inputs"
                v-model="contacts"
                placeholder="请输入联系人"
              />
            </div>
            <div class="titleBox">
              <div>联系方式:</div>
              <input
                disabled
                class="inputs"
                v-model="phone"
                placeholder="请输入联系方式"
              />
            </div>
            <div class="titleBox">
              <div>邮寄地址:</div>
              <input
                disabled
                class="inputs"
                v-model="address"
                placeholder="请输入邮寄详细地址"
              />
            </div>
            <!-- <div class="titleBox">
              <div>兑换码:</div>
              <div>{{ exchangedata.exchange_num }}</div>
            </div> -->
            <!-- <div class="titleBox">
              <div>物流单号:</div>
              <div>{{ exchangedata.send_num | send_num }}</div>
            </div> -->
            <div class="titleBox">
              <div>兑换状态:</div>
              <div>{{ exchangedata.exchange_state | states }}</div>
            </div>
            <!-- <div class="titleBox">
              <div>兑换地点：</div>
              <div>{{ addressdata.address }}</div>
            </div>
            <div class="titleBox">
              <div>兑换时间：</div>
              <div>{{ addressdata.addresstime }}</div>
            </div> -->
          </div>
          <div v-else>
            <div class="titleBox">
              <div>兑换地点：</div>
              <div>{{ addressdata.address }}</div>
            </div>
            <div class="titleBox">
              <div>兑换时间：</div>
              <div>{{ addressdata.addresstime }}</div>
            </div>
            <div class="titleBox">
              <div>兑换码:</div>
              <div>{{ exchangedata.exchange_num }}</div>
            </div>

            <div class="titleBox">
              <div>兑换状态:</div>
              <div>{{ exchangedata.exchange_state | states }}</div>
            </div>
          </div>
          <div>
            <div v-if="radio == 3" class="tip">
              <div>
                *若在未发货前，可用兑换码前往兑换地点兑换，可在个人中心兑换记录中查看兑换记录
              </div>
            </div>
            <div v-else class="tip">
              <div>
                *请自行前往兑换地点凭兑换码兑换,可在个人中心兑换记录中查看兑换记录
              </div>
            </div>
          </div>
          <div class="BottomBtn">
            <div class="txt">
              <el-button class="BottomB" @click="enter()">我明白了</el-button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { get_exchange } from "../../api/exchange";
import { get_addressdata } from "../../api/addressdata";

export default {
  name: "ExchangeDetail",
  data() {
    return {
      activeName: "second",
      radio: 3,
      contacts: "",
      phone: "",
      address: "",
      exchangedata: {},
      addressdata: ""
    };
  },
  filters: {
    states(val) {
      if (val) {
        return "已成功兑换";
      } else {
        return "未完成兑换";
      }
    },
    send_num(val) {
      if (val) {
        return val;
      } else {
        return "暂未发货";
      }
    }
  },
  async created() {
    console.log(this.$route.query);
    var exchanges = await get_exchange({ query: this.$route.query });
    console.log(exchanges.data[0]);
    if (exchanges.data[0].exchangeTpye == "自提") {
      this.radio = 6;
    } else {
      this.contacts = exchanges.data[0].receiving_address.contacts;
      this.phone = exchanges.data[0].receiving_address.phone;
      this.address = exchanges.data[0].receiving_address.address;
    }
    this.exchangedata = exchanges.data[0];
    console.log(this.contacts, this.phone, this.address);
    var addressdata = await get_addressdata({ query: {} });
    console.log("地址", addressdata.data);
    this.addressdata = addressdata.data[0];
  },
  components: {},
  methods: {
    back() {
      this.$router.go(-3); //返回上一层
    },
    SelectGoods(e) {
      console.log(e);
    },
    navigationSelect(path) {
      this.$router.push(path);
    },
    async enter() {
      this.$router.push({
        path: "/personalCenter", //跳转路径
        name: "personalCenter", //跳转路径的name值，不写跳转后页面取不到参数
        // 参数 兑换记录
        query: {
          work: 6
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.main {
  height: 800px;
  background-color: #ffffff;
  .Box {
    width: 80%;
    min-width: 1000px;
    margin: 0px auto;
    padding: 30px 0 0 0;
    display: flex;
    flex-direction: column;
    .back {
      margin: 10px 0;
      cursor: pointer;
    }
    .Title {
      font-size: 28px;
      border-bottom: solid 1px #bbbbbb;
      height: 80px;
      font-weight: 550;
      display: flex;
      flex-direction: column;
      justify-content: center;
      .Stitle {
        font-size: 14px;
        font-weight: 100;
        margin: 5px 0;
      }
    }
    .orderBox {
      height: auto;
      display: flex;
      flex-direction: column;
      align-items: center;
      border-bottom: solid 1px #bbbbbb;
      .title {
        display: flex;
        width: 300px;
        margin: 20px 0 20px 0;
        justify-content: space-between;
      }
      .titleBox {
        display: flex;
        width: 280px;
        margin: 30px 0 0 0;
        justify-content: space-between;
      }
      .tip {
        display: flex;
        width: 280px;
        font-size: 13px;
        color: #c70000;
        margin: 30px 0 0 0;
        justify-content: space-between;
      }
      .inputs {
        border: 0;
        border-bottom: 1.2px solid #c7c5c5;
      }
    }
    .BottomBtn {
      width: 80%;
      height: 100px;
      margin: 30px auto 0;
      align-items: center;
      align-content: center;
      display: flex;
      align-content: center;
      justify-content: center;
      .txt {
        display: flex;
        flex-direction: column;
        align-content: center;
        height: 100px;
        color: saddlebrown;
        align-items: center;
        font-size: 14px;
        .BottomB {
          background-color: #1d2f70;
          color: #ffffff;
          width: 240px;
          height: 50px;
        }
      }
    }
  }
}
</style>
